package com.boyadegroot.divelog.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DiveLogDatabaseHelper extends SQLiteOpenHelper {

    private static final String TAG = DiveLogDatabaseHelper.class.getName();

    public DiveLogDatabaseHelper(Context context) {
        super(context, DiveLogDatabaseContract.DATABASE_NAME, null, DiveLogDatabaseContract.DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DiveLogDatabaseContract.DiveCountries.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveLocations.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveSites.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveTrips.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveCenters.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveOrganizations.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveCourses.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveCertifications.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.Divers.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveBuddies.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.Dives.SQL_CREATE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveSamples.SQL_CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(DiveLogDatabaseContract.DiveCountries.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveLocations.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveSites.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveTrips.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveCenters.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveOrganizations.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveCourses.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveCertifications.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.Divers.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveBuddies.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.Dives.SQL_DELETE_TABLE);
        db.execSQL(DiveLogDatabaseContract.DiveSamples.SQL_DELETE_TABLE);
        onCreate(db);
    }
    
    @Override
    public void onConfigure(SQLiteDatabase db) {
        db.setForeignKeyConstraintsEnabled(true);
    }
}
